package com.druid.response;

import com.druid.common.ConstantCache;
import com.druid.entity.CeSecurityRole;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;

@SuppressWarnings("unused")
@Data
@ApiModel(value="AdminUserVm对象", description="管理员列表视图层对象")
public class AdminUserVm {

    @ApiModelProperty(value = "用户ID")
    private Integer id;

    @ApiModelProperty(value = "用户名称")
    private String username;

    @JsonIgnore
    @ApiModelProperty(value = "用户密码")
    private String password;

    @ApiModelProperty(value = "用户邮箱")
    private String email;

    @JsonIgnore
    @ApiModelProperty(value = "加密盐值")
    private String salt;

    @ApiModelProperty(value = "角色id")
    private Integer roleId;

    @ApiModelProperty(value = "角色名称")
    private String roleName;
    public String getRoleName() {

        List<CeSecurityRole> securityRoleListCache = ConstantCache.getSecurityRoleListCache();
        Optional<CeSecurityRole> first = securityRoleListCache.stream().filter(ceSecurityRole -> this.getRoleId().equals(ceSecurityRole.getRoleId())).findFirst();
        return first.map(CeSecurityRole::getName).orElse(null);
    }

    @ApiModelProperty(value = "是否激活false-否；true-是")
    private Boolean status;
    @ApiModelProperty(value = "是否激活字符串形式")
    private String statusString;
    public String getStatusString() {
        return this.getStatus()?"已激活":"未激活";
    }

    @ApiModelProperty(value = "注册时间")
    private LocalDateTime addTime;

    @ApiModelProperty(value = "注册时间字符串形式")
    private String addTimeString;

    public String getAddTimeString() {

        return null==this.getAddTime()?null:this.getAddTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}
